/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.util.geometricProperties;

import java.util.ArrayList;
import java.util.ListIterator;

/** A class representing DomainDiscretizedGeometricProperties
* @author CENOURA!!!, Pitangueira, Fuina
* @since 22/11/2006
*/

public class DomainDiscretizedGeometricProperties implements
		GeometricProperties {
	
	private ArrayList<IGeometricPoint> geomPoints;
	
	public DomainDiscretizedGeometricProperties(){
	}
	
	public DomainDiscretizedGeometricProperties(ArrayList<IGeometricPoint> a){
		this.setGeomPoints(a);
	}
	
	/**
	 * @return Returns the geomPoints.
	 */
	public ArrayList<IGeometricPoint> getGeomPointsList() {
		return geomPoints;
	}

	/**
	 * @param geomPoints The geomPoints to set.
	 */
	public void setGeomPoints(ArrayList<IGeometricPoint> geomPoints) {
		this.geomPoints = geomPoints;
	}
	
	public int getNumberOfGeometricPoints(){
		return (geomPoints.size());
	};
	
	public IGeometricPoint getGeometricPoint(double y, double z) {
		IGeometricPoint g;
		ListIterator gs = this.geomPoints.listIterator();
		while (gs.hasNext()) {
			g = (IGeometricPoint) gs.next();
			if (g.getPoint().y == y && g.getPoint().z == z && g.getPoint().x == 0) {
				return (g);
			};
		};
		return (null);
	};
    
	public IGeometricPoint getGeometricPoint(double x, double y, double z) {
		IGeometricPoint g;
		ListIterator gs = this.geomPoints.listIterator();
		while (gs.hasNext()) {
			g = (IGeometricPoint) gs.next();
			if (g.getPoint().x == x && g.getPoint().y == y && g.getPoint().z == z) {
				return (g);
			};
		};
		return (null);
	};
	
	public void add(IGeometricPoint a) {
		geomPoints.add(a);
	};
	
	public void remove(IGeometricPoint a) {
		geomPoints.remove(a);
	};

	/* (non-Javadoc)
	 * @see br.ufmg.dees.insane.util.geometricProperties.GeometricProperties#getArea()
	 */
	public double getArea(){
		IGeometricPoint g;
		double volume=0.0;
		ListIterator gs = this.geomPoints.listIterator();
		while (gs.hasNext()) {
			g = (IGeometricPoint) gs.next();
			volume+=g.getVolume().getDy()*g.getVolume().getDz();
		};
		return (volume);
	};
	
	/* (non-Javadoc)
	 * @see br.ufmg.dees.insane.util.geometricProperties.GeometricProperties#getInertiaY()
	 */
	public double getInertiaY(){
		IGeometricPoint g;
		double inertiaY=0.0;
		ListIterator gs = this.geomPoints.listIterator();
		while (gs.hasNext()) {
			g = (IGeometricPoint) gs.next();
			inertiaY+=g.getVolume().volume()*g.getPoint().z*g.getPoint().z;
		};
		return (inertiaY);
	};
	
	/* (non-Javadoc)
	 * @see br.ufmg.dees.insane.util.geometricProperties.GeometricProperties#getInertiaZ()
	 */
	public double getInertiaZ(){
		IGeometricPoint g;
		double inertiaZ=0.0;
		ListIterator gs = this.geomPoints.listIterator();
		while (gs.hasNext()) {
			g = (IGeometricPoint) gs.next();
			inertiaZ+=g.getVolume().volume()*g.getPoint().y*g.getPoint().y;
		};
		return (inertiaZ);
	};
	
	/* (non-Javadoc)
	 * @see br.ufmg.dees.insane.util.geometricProperties.GeometricProperties#getInertiaX()
	 */
	public double getInertiaX(){
		double inertiaPolar=0.0;
		inertiaPolar = this.getInertiaY()+this.getInertiaZ();
		return (inertiaPolar);
	};
	
	/* (non-Javadoc)
	 * @see br.ufmg.dees.insane.util.geometricProperties.GeometricProperties#getThickness()
	 */
	public double getThickness(){
		return ((IGeometricPoint)this.geomPoints.get(0)).getPoint().distance(((IGeometricPoint)this.geomPoints.get(this.geomPoints.size()-1)).getPoint());
	}
	
//	/** Returns the volume of this geometricPoint.
//	 *  @return the volume of this geometricPoint.
//	 */
//	public double getVolume(){
//		IGeometricPoint g;
//		double volume=0.0;
//		ListIterator gs = this.geomPoints.listIterator();
//		while (gs.hasNext()) {
//			g = (IGeometricPoint) gs.next();
//			volume+=g.getVolume().volume();
//		};
//		return (volume);
//	};

}
